package com.loan.controller.app.index;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.system.domain.IndexApplyProductEntity;
import com.loan.system.domain.PayBankEntity;
import com.loan.system.service.IndexApplyProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shiguang on 2022/9/16 10:20
 */
@Validated
@Api(value = "首页贷款金额管理", tags = {"首页贷款金额管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/index")
public class IndexApplyProductController extends BaseController {

    private final IndexApplyProductService indexApplyProductService;

    /**
     * 获取首页贷款金额列表
     */
    @ApiOperation("获取首页贷款金额列表")
    //@SaCheckPermissio("app:index:list")
    @GetMapping("/page")
    public TableDataInfo<IndexApplyProductEntity> list(IndexApplyProductEntity entity, PageQuery pageQuery) {
        return indexApplyProductService.selectPageList(entity, pageQuery);
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:index:query")
    @GetMapping(value = {"/{id}"})
    public Result<IndexApplyProductEntity> getInfo(@ApiParam("ID") @PathVariable(value = "id", required = false) Long id) {
        if (ObjectUtil.isNotNull(id)) {
            return Result.ok(indexApplyProductService.selectById(id));
        }
        return Result.ok();
    }

    /**
     * 新增首页贷款金额数据
     */
    @ApiOperation("新增首页贷款金额数据")
    //@SaCheckPermissio("app:index:add")
    @Log(title = "新增首页贷款金额数据", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody IndexApplyProductEntity entity) {
        return toAjax(indexApplyProductService.add(entity));
    }

    /**
     * 修改首页贷款金额数据
     */
    @ApiOperation("修改首页贷款金额数据")
    //@SaCheckPermissio("app:index:update")
    @Log(title = "修改首页贷款金额数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody IndexApplyProductEntity entity) {
        return toAjax(indexApplyProductService.update(entity));
    }

    /**
     * 删除数据
     */
    @ApiOperation("删除数据")
    //@SaCheckPermissio("app:index:remove")
    @Log(title = "删除数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(indexApplyProductService.deleteById(id));
    }
}
